package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class AdvertisementActivity extends AppCompatActivity implements View.OnClickListener {
    Button Btn_Pass;
    private int time = 5;
    //判断跳过按钮是否被点击 是则为0，否则为1
    private int close = 1;
    private static final String TAG = "AdvertisementActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advertisement);

        Btn_Pass = findViewById(R.id.Btn_Pass);

            Btn_Pass.setOnClickListener(this);


        show();


    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(AdvertisementActivity.this,LoginActivity.class);
        startActivity(intent);
        close = 0;
    }

    private void show() {
        final Thread thread = new Thread();

        new Thread(new Runnable() {
            @Override
            public void run() {

                while (time > 0){
                    time--;
                    try {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Btn_Pass.setText("跳过 "+(time+1)+"S");
                            }
                        });

                        thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.e(TAG, "run: "+ close);
                    if (time==0 && close == 1){
                        Intent intent = new Intent(AdvertisementActivity.this,LoginActivity.class);
                        startActivity(intent);
                    }
                }

            }

        }

        ).start();
    }


}